package com.bella.api.system.controller;

import com.bella.api.system.dto.role.RoleDto;
import com.bella.api.system.dto.role.RoleQueryDto;
import com.bella.api.system.service.RoleService;
import com.bella.api.utils.ApiResponse;
import com.bella.api.utils.ApiResponseCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author zsq
 * @create 2020-05-13-17:11
 */
@Api(description = "角色操作接口")
@RestController
@RequestMapping("/web/v1/role")
public class RoleController {
    @Autowired
    RoleService roleService;

    @ApiOperation(value = "获取角色列表分页", notes = "获取角色列表分页")
    @RequestMapping(value = "/roleListByPage", method = RequestMethod.GET)
    public ApiResponse roleList(@ModelAttribute RoleQueryDto roleQueryDto) {
        return new ApiResponse(ApiResponseCode.SUCCESS, roleService.getRoleList(roleQueryDto));
    }

    @ApiOperation(value = "获取所有角色列表", notes = "获取所有角色列表")
    @RequestMapping(value = "/getRoleList", method = RequestMethod.GET)
    public ApiResponse getRoleList() {
        return new ApiResponse(ApiResponseCode.SUCCESS, roleService.getRoleList());
    }

    @ApiOperation(value = "角色详情", notes = "角色详情")
    @RequestMapping(value = "/roleDetail/{id}", method = RequestMethod.GET)
    public ApiResponse roleDetail(@PathVariable("id") Integer id) {
        return new ApiResponse(ApiResponseCode.SUCCESS, roleService.roleDetail(id));
    }

    @ApiOperation(value = "新增角色", notes = "新增角色")
    @RequestMapping(value = "/addRole", method = RequestMethod.POST)
    public ApiResponse addRole(@RequestBody RoleDto addRoleDto) {
        roleService.addRole(addRoleDto);
        return new ApiResponse(ApiResponseCode.SUCCESS);
    }

    @ApiOperation(value = "修改角色", notes = "修改角色")
    @RequestMapping(value = "/updRole", method = RequestMethod.POST)
    public ApiResponse updRole(@RequestBody RoleDto addRoleDto) {
        roleService.updRole(addRoleDto);
        return new ApiResponse(ApiResponseCode.SUCCESS);
    }

    @ApiOperation(value = "删除角色", notes = "删除角色")
    @RequestMapping(value = "/deleteRole", method = RequestMethod.POST)
    public ApiResponse deleteRole(@RequestBody RoleDto addRoleDto) {
        roleService.deleteRole(addRoleDto);
        return new ApiResponse(ApiResponseCode.SUCCESS);
    }
}
